package io.geekidea.springbootplus.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.system.entity.Advertise;
import io.geekidea.springbootplus.system.entity.SysUser;
import io.geekidea.springbootplus.system.mapper.AdvertiseMapper;
import io.geekidea.springbootplus.system.param.AdvertisePageParam;
import io.geekidea.springbootplus.system.param.AdvertiseStatusParam;
import io.geekidea.springbootplus.system.service.AdvertiseService;
import io.geekidea.springbootplus.system.vo.AdvertiseQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class AdvertiseServiceImpl extends BaseServiceImpl<AdvertiseMapper, Advertise> implements AdvertiseService {

    @Resource
    private AdvertiseMapper sysAdvertiseMapper;

    @Override
    public boolean addSysAdvertise(AdvertiseQueryVo sysAdvertise) throws Exception {
        return sysAdvertiseMapper.insertSysAdvertise(sysAdvertise) >0;
    }

    @Override
    public boolean updateSysAdvertise(AdvertiseQueryVo sysAdvertise) throws Exception {
        return sysAdvertiseMapper.updateSysAdvertise(sysAdvertise) >0;
    }

    @Override
    public boolean deleteSysAdvertiseById(Integer id) throws Exception {
        return sysAdvertiseMapper.deleteSysAdvertiseById(id) >0;
    }

    @Override
    public boolean deleteAllAdvertise(List<Integer> ids) throws Exception {
        return sysAdvertiseMapper.deleteAllAdvertise(ids) >0;
    }

    @Override
    public Paging<AdvertiseQueryVo> getSysAdvertisePageList(AdvertisePageParam advertisePageParam) throws Exception {
        Page<AdvertiseQueryVo> page = new PageInfo<>(advertisePageParam);
        IPage<AdvertiseQueryVo> advertisePageList = sysAdvertiseMapper.getSysAdvertisePageList(page, advertisePageParam);
        return new Paging(advertisePageList);
    }

    @Override
    public AdvertiseQueryVo findAdvertiseById(Integer id) {
        return sysAdvertiseMapper.slectAdvertiseById(id);
    }


    @Override
    public boolean updateAdvertiseStatus(AdvertiseStatusParam advertiseStatusParam) {
        return sysAdvertiseMapper.updateAdvertiseStatus(advertiseStatusParam)>0;
    }
}
